<?php


namespace App\Service\Gaode;

use GuzzleHttp\HandlerStack;
use Hyperf\Guzzle\ClientFactory;
use GuzzleHttp\Client;
use Hyperf\Guzzle\CoroutineHandler;

class ApiClient
{
    /**
     * @var Client
     */
    public $client;

    /**
     * @var \Hyperf\Guzzle\ClientFactory
     */
    protected $clientFactory;


    public function __construct(ClientFactory $clientFactory)
    {
        $this->clientFactory = $clientFactory;
        $this->getClient();
    }


    public function getClient()
    {
        $this->client = $this->clientFactory->create([
            'base_uri' => 'https://restapi.amap.com',
            'timeout' => 3,
        ]);

    }

    /**
     * request
     * @param array $array
     * @return string
     * @throws \GuzzleHttp\Exception\GuzzleException
     * date:2022/7/13
     * time:14:49
     * auth：xyc
     */
    public function request(array $array)
    {
        return $this->client->request(...$array)->getBody()->getContents();
    }
}